package son.vpoint.dinokids;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity implements OnClickListener {
	private static Button btnPlaygame;
	private static Button btnHighScore;
	private static Button btnInfor;
	private static Button btnMoregame;
	private static Button btnSound;
	
@Override
protected void onCreate(Bundle savedInstanceState) {
	
	// TODO Auto-generated method stub
	super.onCreate(savedInstanceState);
	requestWindowFeature(Window.FEATURE_NO_TITLE);
	 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
	setContentView(R.layout.main);
	btnPlaygame = (Button)findViewById(R.id.btnPlaygame);
	btnPlaygame.setOnClickListener(this);
	btnHighScore =(Button)findViewById(R.id.btnHighscore);
	btnHighScore.setOnClickListener(this);
	btnMoregame =(Button)findViewById(R.id.btnMoregame);
	btnMoregame.setOnClickListener(this);
	btnSound =(Button)findViewById(R.id.btnSound);
	btnSound.setOnClickListener(this);
	btnInfor =(Button)findViewById(R.id.btnInfor);
	btnInfor.setOnClickListener(this);
}
public void onClick(View v) {
	switch (v.getId()) {
	case R.id.btnPlaygame:
		Animation anim = AnimationUtils.loadAnimation(getBaseContext(), R.anim.grow_fade_in_center);
		final View btn = (Button)findViewById(R.id.btnPlaygame);
		btn.setAnimation(anim);
		btn.startAnimation(anim);
		anim.setAnimationListener(new AnimationListener() {
			
			public void onAnimationStart(Animation animation) {
//				btnPlaygame.setBackgroundResource(R.drawable.btn_play_normal);
				
			}
			
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			public void onAnimationEnd(Animation animation) {
				Intent i = new Intent(MainActivity.this, OperatorSelected.class);
				MainActivity.this.startActivity(i);
				MainActivity.this.finish();
				overridePendingTransition(R.anim.push_up_in, R.anim.push_up_out);
		
				
			}
		});
		
		break;
	case R.id.btnHighscore:
		Animation anim1 = AnimationUtils.loadAnimation(getBaseContext(), R.anim.grow_fade_in_center);
		final View btn1 = (Button)findViewById(R.id.btnHighscore);
		btn1.setAnimation(anim1);
		btn1.startAnimation(anim1);
		anim1.setAnimationListener(new AnimationListener() {
			
			public void onAnimationStart(Animation animation) {
//				btnPlaygame.setBackgroundResource(R.drawable.btn_play_normal);
				
			}
			
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			public void onAnimationEnd(Animation animation) {
				
				overridePendingTransition(R.anim.push_up_in, R.anim.push_up_out);
				
			}
		});
		
		break;
	case R.id.btnInfor:
		Animation anim2 = AnimationUtils.loadAnimation(getBaseContext(), R.anim.grow_fade_in_center);
		final View btn2 = (Button)findViewById(R.id.btnInfor);
		btn2.setAnimation(anim2);
		btn2.startAnimation(anim2);
		anim2.setAnimationListener(new AnimationListener() {
			
			public void onAnimationStart(Animation animation) {
//				btnPlaygame.setBackgroundResource(R.drawable.btn_play_normal);
				
			}
			
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			public void onAnimationEnd(Animation animation) {
				Intent i = new Intent(MainActivity.this, Infomation.class);
				startActivity(i);
				finish();
				overridePendingTransition(R.anim.push_up_in, R.anim.push_up_out);
				
			}
		});
		
		break;
	case R.id.btnMoregame:
		Animation anim3 = AnimationUtils.loadAnimation(getBaseContext(), R.anim.grow_fade_in_center);
		final View btn3 = (Button)findViewById(R.id.btnMoregame);
		btn3.setAnimation(anim3);
		btn3.startAnimation(anim3);
		anim3.setAnimationListener(new AnimationListener() {
			
			public void onAnimationStart(Animation animation) {
//				btnPlaygame.setBackgroundResource(R.drawable.btn_play_normal);
				
			}
			
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			public void onAnimationEnd(Animation animation) {

				overridePendingTransition(R.anim.push_up_in, R.anim.push_up_out);
				
			}
		});
		
		break;
	case R.id.btnSound:
		Animation anim4 = AnimationUtils.loadAnimation(getBaseContext(), R.anim.grow_fade_in_center);
		final View btn4 = (Button)findViewById(R.id.btnSound);
		btn4.setAnimation(anim4);
		btn4.startAnimation(anim4);
		anim4.setAnimationListener(new AnimationListener() {
			
			public void onAnimationStart(Animation animation) {
//				btnPlaygame.setBackgroundResource(R.drawable.btn_play_normal);
				
			}
			
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			public void onAnimationEnd(Animation animation) {
				
				overridePendingTransition(R.anim.push_up_in, R.anim.push_up_out);
				
			}
		});
		
		break;
		

	default:
		break;
	}
	
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_BACK) {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setTitle("Exit!")
				.setMessage("Are you sure you want to exit?")
				.setCancelable(false)
				.setPositiveButton("OK", new DialogInterface.OnClickListener() {
					
					public void onClick(DialogInterface dialog, int which) {
						MainActivity.this.finish();
						
					}

			



				})
				.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
					
					public void onClick(DialogInterface dialog, int which) {
						dialog.cancel();
						
					}
				});
		builder.create().show();
				
		
	}
	
	return super.onKeyDown(keyCode, event);
}


}
